<?php

/**
 * This is the model class for table "setting".
 *
 * The followings are the available columns in table 'setting':
 * @property integer $id
 * @property string $name
 * @property string $address1
 * @property string $address2
 * @property string $tel1
 * @property string $tel2
 * @property string $mail
 * @property string $kurs_nal
 * @property string $kurs_bn
 */
class Setting extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Setting the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'setting';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, address1, address2, tel1, tel2, mail, kurs_nal, kurs_bn', 'required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, address1, address2, tel1, tel2, mail, kurs_nal, kurs_bn', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Назва компанії',
			'address1' => 'Адрес №1 (Країна, місто)',
			'address2' => 'Адрес №2 (вулиця, будинок...)',
			'tel1' => 'Телефон №1',
			'tel2' => 'Телефон №2',
			'mail' => 'Mail',
			'kurs_nal' => 'Курс валюти - налічка',
			'kurs_bn' => 'Курс валюти безнал',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('address1',$this->address1,true);
		$criteria->compare('address2',$this->address2,true);
		$criteria->compare('tel1',$this->tel1,true);
		$criteria->compare('tel2',$this->tel2,true);
		$criteria->compare('mail',$this->mail,true);
		$criteria->compare('kurs_nal',$this->kurs_nal,true);
		$criteria->compare('kurs_bn',$this->kurs_bn,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public static function get_settings(){
		$setting=self::model()->findByPk(1);

		return $setting;
	}
}